﻿// Sequin.WebLogs.Sessions.Session
//
// (c) 2011 Arthur Pitman
//
// Part of the Sequin Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License (Version 2.1) as published by the Free Software Foundation.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License (Version 2.1) along with this library; if not, write to the 
// Free Software Foundation, Inc., 
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
// or see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sequin.WebLogs.Sessions
{
	/// <summary>
	/// Represents a <see cref="Session"/>, i.e. a contiguous collection of <see cref="LogEntry"/> objects
	/// </summary>
	public class Session
	{
		/// <summary>
		/// Identifier for the <see cref="Session"/>
		/// </summary>
		public int Id { get; protected set; }

		/// <summary>
		/// The collection of <see cref="LogEntry"/> instances in the <see cref="Session"/>
		/// </summary>
		public List<LogEntry> Entries { get; protected set; }

		/// <summary>
		/// The last <see cref="LogEntry"/> in the <see cref="Session"/>
		/// </summary>
		public LogEntry LastEntry { get; protected set; }
	
		/// <summary>
		/// Initializes a new <see cref="Session"/> instance
		/// </summary>
		/// <param name="id">The identifier for the session</param>
		/// <param name="entry">The first <see cref="LogEntry"/>, or <c>null</c> for none</param>
		public Session(int id = 0, LogEntry entry = null)
		{
			Id = id;
			Entries = new List<LogEntry>();
			if (entry == null)
				LastEntry = null;
			else
				AddEntry(entry);
		}

		/// <summary>
		/// Adds a <see cref="LogEntry"/> to the <see cref="Session"/>
		/// </summary>
		/// <param name="entry">The <see cref="LogEntry"/> to add</param>
		public void AddEntry(LogEntry entry)
		{
			Entries.Add(entry);
			LastEntry = entry;
		}
	}
}
